package com.dykj.fireFighting.web.controller.GB26875Controller;

import com.dykj.fireFighting.web.contact.PubContacts;
import com.dykj.fireFighting.web.utils.HttpClient;
import com.dykj.fireFighting.web.utils.ReturnUtil;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/port")
public class GetPortController {
    @GetMapping("/getPort")
    @ResponseBody
    public ModelMap getList(String address, int portNum, int portTotal){
        Map<String,Object> map=new HashMap<>();
        map.put("address",address);
        map.put("portNum",portNum);
        map.put("portTotal",portTotal);
        String s= HttpClient.doPost(PubContacts.address+"getPort",map);
        JSONObject obj = new JSONObject().fromObject(s);
        return ReturnUtil.Success("搜索成功", obj.get("port"));
    }

    @GetMapping("/openPort")
    @ResponseBody
    public ModelMap openPort(int port, int openType){
        Map<String,Object> map=new HashMap<>();
        map.put("port",port);
        map.put("openType",openType);
        String s= HttpClient.doPost(PubContacts.address+"openPort",map);
        JSONObject obj = new JSONObject().fromObject(s);
        return ReturnUtil.Success("操作成功", obj.get("status"));
    }

    @GetMapping("/index")
    public String getIndex() {
        return "port/index";
    }
}
